#define _BSD_SOURCE
#define _XOPEN_SOURCE 500
#include <assert.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>

#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>


int read_dma(int fpga, uint32_t addr, uint32_t size,void* dstaddr)
{
	int rc;
	char *buffer = NULL;
	buffer = dstaddr;
	/* select AXI MM address */
	off_t off = lseek(fpga, addr, SEEK_SET);
	/* read data from AXI MM into buffer using SGDMA */
	rc = read(fpga, buffer, size);
	if ((rc > 0) && (rc < size))
	{
		printf(
				"Short read of %d bytes into a %d bytes buffer, could be a packet read?\n",
				rc, size);
	}
	return 0;
}

int write_dma(int fpga, uint32_t addr, uint32_t size, void* srcaddr)
{
	int rc;
	char *buffer = NULL;
	char *allocated = NULL;

	buffer = srcaddr;

    /* select AXI MM address */
    off_t off = lseek(fpga, addr, SEEK_SET);
    /* write buffer to AXI MM address using SGDMA */
    rc = write(fpga, buffer, size);
	return 0;
}
